import os

from utils import Timer, urllist
from modules.mp3downloader import Mp3Downloader
from modules.storager import Storager
from modules.hasher import Hasher


def download_and_save():
    downloader = Mp3Downloader()
    tick = Timer()
    contents = downloader.process_multi_thread(urllist())
    print(f'{tick.tick()}s')

    tick = Timer()
    sto = Storager()
    sto.set_file_save_path('mp3')
    sto.process_multi_thread(contents)
    print(f'process_multi_process {tick.tick()}s')


def hash_op():
    contents = []
    for p, d, file_list in os.walk('mp3'):
        for f in file_list:
            file_path = rf'{p}/{f}'
            with open(file_path, 'rb') as fp:
                data = fp.read()
                contents.append(data)

    tick = Timer()
    h = Hasher()
    h.process_single_thread(contents)
    print(f'process_single_thread {tick.tick()}s')
    h.process_multi_thread(contents)
    print(f'process_multi_thread {tick.tick()}s')
    h.process_multi_process(contents)
    print(f'process_multi_process {tick.tick()}s')


if __name__ == '__main__':
    download_and_save()
    # hash_op()
